<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>labelinput.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_ui_labelinput.js.html">labelinput.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview This behavior is applied to a text input and it shows a text
<a name="line17"></a> * message inside the element if the user hasn&#39;t entered any text.
<a name="line18"></a> *
<a name="line19"></a> * This uses the HTML5 placeholder attribute where it is supported.
<a name="line20"></a> *
<a name="line21"></a> * This is ported from http://go/labelinput.js
<a name="line22"></a> *
<a name="line23"></a> * Known issue: Safari does not allow you get to the window object from a
<a name="line24"></a> * document. We need that to listen to the onload event. For now we hard code
<a name="line25"></a> * the window to the current window.
<a name="line26"></a> *
<a name="line27"></a> * Known issue: We need to listen to the form submit event but we attach the
<a name="line28"></a> * event only once (when created or when it is changed) so if you move the DOM
<a name="line29"></a> * node to another form it will not be cleared correctly before submitting.
<a name="line30"></a> *
<a name="line31"></a> * Known issue: Where the placeholder attribute isn&#39;t supported, screen reader
<a name="line32"></a> * users encounter trouble because the label is deleted upon focus. For now we
<a name="line33"></a> * set the &quot;aria-label&quot; attribute.
<a name="line34"></a> *
<a name="line35"></a> * @author arv@google.com (Erik Arvidsson)
<a name="line36"></a> * @see ../demos/labelinput.html
<a name="line37"></a> */
<a name="line38"></a>
<a name="line39"></a>goog.provide(&#39;goog.ui.LabelInput&#39;);
<a name="line40"></a>
<a name="line41"></a>goog.require(&#39;goog.Timer&#39;);
<a name="line42"></a>goog.require(&#39;goog.a11y.aria&#39;);
<a name="line43"></a>goog.require(&#39;goog.a11y.aria.State&#39;);
<a name="line44"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line45"></a>goog.require(&#39;goog.dom&#39;);
<a name="line46"></a>goog.require(&#39;goog.dom.classlist&#39;);
<a name="line47"></a>goog.require(&#39;goog.events.EventHandler&#39;);
<a name="line48"></a>goog.require(&#39;goog.events.EventType&#39;);
<a name="line49"></a>goog.require(&#39;goog.ui.Component&#39;);
<a name="line50"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line51"></a>
<a name="line52"></a>
<a name="line53"></a>
<a name="line54"></a>/**
<a name="line55"></a> * This creates the label input object.
<a name="line56"></a> * @param {string=} opt_label The text to show as the label.
<a name="line57"></a> * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper.
<a name="line58"></a> * @extends {goog.ui.Component}
<a name="line59"></a> * @constructor
<a name="line60"></a> */
<a name="line61"></a>goog.ui.LabelInput = function(opt_label, opt_domHelper) {
<a name="line62"></a>  goog.ui.Component.call(this, opt_domHelper);
<a name="line63"></a>
<a name="line64"></a>  /**
<a name="line65"></a>   * The text to show as the label.
<a name="line66"></a>   * @type {string}
<a name="line67"></a>   * @private
<a name="line68"></a>   */
<a name="line69"></a>  this.label_ = opt_label || &#39;&#39;;
<a name="line70"></a>};
<a name="line71"></a>goog.inherits(goog.ui.LabelInput, goog.ui.Component);
<a name="line72"></a>
<a name="line73"></a>
<a name="line74"></a>/**
<a name="line75"></a> * Variable used to store the element value on keydown and restore it on
<a name="line76"></a> * keypress.  See {@link #handleEscapeKeys_}
<a name="line77"></a> * @type {?string}
<a name="line78"></a> * @private
<a name="line79"></a> */
<a name="line80"></a>goog.ui.LabelInput.prototype.ffKeyRestoreValue_ = null;
<a name="line81"></a>
<a name="line82"></a>
<a name="line83"></a>/**
<a name="line84"></a> * The label restore delay after leaving the input.
<a name="line85"></a> * @type {number} Delay for restoring the label.
<a name="line86"></a> * @protected
<a name="line87"></a> */
<a name="line88"></a>goog.ui.LabelInput.prototype.labelRestoreDelayMs = 10;
<a name="line89"></a>
<a name="line90"></a>
<a name="line91"></a>/**
<a name="line92"></a> * Indicates whether the browser supports the placeholder attribute, new in
<a name="line93"></a> * HTML5.
<a name="line94"></a> * @type {boolean}
<a name="line95"></a> * @private
<a name="line96"></a> */
<a name="line97"></a>goog.ui.LabelInput.SUPPORTS_PLACEHOLDER_ = (
<a name="line98"></a>    &#39;placeholder&#39; in document.createElement(&#39;input&#39;));
<a name="line99"></a>
<a name="line100"></a>
<a name="line101"></a>/**
<a name="line102"></a> * @type {goog.events.EventHandler}
<a name="line103"></a> * @private
<a name="line104"></a> */
<a name="line105"></a>goog.ui.LabelInput.prototype.eventHandler_;
<a name="line106"></a>
<a name="line107"></a>
<a name="line108"></a>/**
<a name="line109"></a> * @type {boolean}
<a name="line110"></a> * @private
<a name="line111"></a> */
<a name="line112"></a>goog.ui.LabelInput.prototype.hasFocus_ = false;
<a name="line113"></a>
<a name="line114"></a>
<a name="line115"></a>/**
<a name="line116"></a> * Creates the DOM nodes needed for the label input.
<a name="line117"></a> * @override
<a name="line118"></a> */
<a name="line119"></a>goog.ui.LabelInput.prototype.createDom = function() {
<a name="line120"></a>  this.setElementInternal(
<a name="line121"></a>      this.getDomHelper().createDom(&#39;input&#39;, {&#39;type&#39;: &#39;text&#39;}));
<a name="line122"></a>};
<a name="line123"></a>
<a name="line124"></a>
<a name="line125"></a>/**
<a name="line126"></a> * Decorates an existing HTML input element as a label input. If the element
<a name="line127"></a> * has a &quot;label&quot; attribute then that will be used as the label property for the
<a name="line128"></a> * label input object.
<a name="line129"></a> * @param {Element} element The HTML input element to decorate.
<a name="line130"></a> * @override
<a name="line131"></a> */
<a name="line132"></a>goog.ui.LabelInput.prototype.decorateInternal = function(element) {
<a name="line133"></a>  goog.ui.LabelInput.superClass_.decorateInternal.call(this, element);
<a name="line134"></a>  if (!this.label_) {
<a name="line135"></a>    this.label_ = element.getAttribute(&#39;label&#39;) || &#39;&#39;;
<a name="line136"></a>  }
<a name="line137"></a>
<a name="line138"></a>  // Check if we&#39;re attaching to an element that already has focus.
<a name="line139"></a>  if (goog.dom.getActiveElement(goog.dom.getOwnerDocument(element)) ==
<a name="line140"></a>      element) {
<a name="line141"></a>    this.hasFocus_ = true;
<a name="line142"></a>    var el = this.getElement();
<a name="line143"></a>    goog.asserts.assert(el);
<a name="line144"></a>    goog.dom.classlist.remove(el, this.LABEL_CLASS_NAME);
<a name="line145"></a>  }
<a name="line146"></a>
<a name="line147"></a>  if (goog.ui.LabelInput.SUPPORTS_PLACEHOLDER_) {
<a name="line148"></a>    this.getElement().placeholder = this.label_;
<a name="line149"></a>    return;
<a name="line150"></a>  }
<a name="line151"></a>  var labelInputElement = this.getElement();
<a name="line152"></a>  goog.asserts.assert(labelInputElement,
<a name="line153"></a>      &#39;The label input element cannot be null.&#39;);
<a name="line154"></a>  goog.a11y.aria.setState(labelInputElement,
<a name="line155"></a>      goog.a11y.aria.State.LABEL,
<a name="line156"></a>      this.label_);
<a name="line157"></a>};
<a name="line158"></a>
<a name="line159"></a>
<a name="line160"></a>/** @override */
<a name="line161"></a>goog.ui.LabelInput.prototype.enterDocument = function() {
<a name="line162"></a>  goog.ui.LabelInput.superClass_.enterDocument.call(this);
<a name="line163"></a>  this.attachEvents_();
<a name="line164"></a>  this.check_();
<a name="line165"></a>
<a name="line166"></a>  // Make it easy for other closure widgets to play nicely with inputs using
<a name="line167"></a>  // LabelInput:
<a name="line168"></a>  this.getElement().labelInput_ = this;
<a name="line169"></a>};
<a name="line170"></a>
<a name="line171"></a>
<a name="line172"></a>/** @override */
<a name="line173"></a>goog.ui.LabelInput.prototype.exitDocument = function() {
<a name="line174"></a>  goog.ui.LabelInput.superClass_.exitDocument.call(this);
<a name="line175"></a>  this.detachEvents_();
<a name="line176"></a>
<a name="line177"></a>  this.getElement().labelInput_ = null;
<a name="line178"></a>};
<a name="line179"></a>
<a name="line180"></a>
<a name="line181"></a>/**
<a name="line182"></a> * Attaches the events we need to listen to.
<a name="line183"></a> * @private
<a name="line184"></a> */
<a name="line185"></a>goog.ui.LabelInput.prototype.attachEvents_ = function() {
<a name="line186"></a>  var eh = new goog.events.EventHandler(this);
<a name="line187"></a>  eh.listen(this.getElement(), goog.events.EventType.FOCUS, this.handleFocus_);
<a name="line188"></a>  eh.listen(this.getElement(), goog.events.EventType.BLUR, this.handleBlur_);
<a name="line189"></a>
<a name="line190"></a>  if (goog.ui.LabelInput.SUPPORTS_PLACEHOLDER_) {
<a name="line191"></a>    this.eventHandler_ = eh;
<a name="line192"></a>    return;
<a name="line193"></a>  }
<a name="line194"></a>
<a name="line195"></a>  if (goog.userAgent.GECKO) {
<a name="line196"></a>    eh.listen(this.getElement(), [
<a name="line197"></a>      goog.events.EventType.KEYPRESS,
<a name="line198"></a>      goog.events.EventType.KEYDOWN,
<a name="line199"></a>      goog.events.EventType.KEYUP
<a name="line200"></a>    ], this.handleEscapeKeys_);
<a name="line201"></a>  }
<a name="line202"></a>
<a name="line203"></a>  // IE sets defaultValue upon load so we need to test that as well.
<a name="line204"></a>  var d = goog.dom.getOwnerDocument(this.getElement());
<a name="line205"></a>  var w = goog.dom.getWindow(d);
<a name="line206"></a>  eh.listen(w, goog.events.EventType.LOAD, this.handleWindowLoad_);
<a name="line207"></a>
<a name="line208"></a>  this.eventHandler_ = eh;
<a name="line209"></a>  this.attachEventsToForm_();
<a name="line210"></a>};
<a name="line211"></a>
<a name="line212"></a>
<a name="line213"></a>/**
<a name="line214"></a> * Adds a listener to the form so that we can clear the input before it is
<a name="line215"></a> * submitted.
<a name="line216"></a> * @private
<a name="line217"></a> */
<a name="line218"></a>goog.ui.LabelInput.prototype.attachEventsToForm_ = function() {
<a name="line219"></a>  // in case we have are in a form we need to make sure the label is not
<a name="line220"></a>  // submitted
<a name="line221"></a>  if (!this.formAttached_ &amp;&amp; this.eventHandler_ &amp;&amp; this.getElement().form) {
<a name="line222"></a>    this.eventHandler_.listen(this.getElement().form,
<a name="line223"></a>                              goog.events.EventType.SUBMIT,
<a name="line224"></a>                              this.handleFormSubmit_);
<a name="line225"></a>    this.formAttached_ = true;
<a name="line226"></a>  }
<a name="line227"></a>};
<a name="line228"></a>
<a name="line229"></a>
<a name="line230"></a>/**
<a name="line231"></a> * Stops listening to the events.
<a name="line232"></a> * @private
<a name="line233"></a> */
<a name="line234"></a>goog.ui.LabelInput.prototype.detachEvents_ = function() {
<a name="line235"></a>  if (this.eventHandler_) {
<a name="line236"></a>    this.eventHandler_.dispose();
<a name="line237"></a>    this.eventHandler_ = null;
<a name="line238"></a>  }
<a name="line239"></a>};
<a name="line240"></a>
<a name="line241"></a>
<a name="line242"></a>/** @override */
<a name="line243"></a>goog.ui.LabelInput.prototype.disposeInternal = function() {
<a name="line244"></a>  goog.ui.LabelInput.superClass_.disposeInternal.call(this);
<a name="line245"></a>  this.detachEvents_();
<a name="line246"></a>};
<a name="line247"></a>
<a name="line248"></a>
<a name="line249"></a>/**
<a name="line250"></a> * The CSS class name to add to the input when the user has not entered a
<a name="line251"></a> * value.
<a name="line252"></a> */
<a name="line253"></a>goog.ui.LabelInput.prototype.LABEL_CLASS_NAME =
<a name="line254"></a>    goog.getCssName(&#39;label-input-label&#39;);
<a name="line255"></a>
<a name="line256"></a>
<a name="line257"></a>/**
<a name="line258"></a> * Handler for the focus event.
<a name="line259"></a> * @param {goog.events.Event} e The event object passed in to the event handler.
<a name="line260"></a> * @private
<a name="line261"></a> */
<a name="line262"></a>goog.ui.LabelInput.prototype.handleFocus_ = function(e) {
<a name="line263"></a>  this.hasFocus_ = true;
<a name="line264"></a>  var el = this.getElement();
<a name="line265"></a>  goog.asserts.assert(el);
<a name="line266"></a>  goog.dom.classlist.remove(el, this.LABEL_CLASS_NAME);
<a name="line267"></a>  if (goog.ui.LabelInput.SUPPORTS_PLACEHOLDER_) {
<a name="line268"></a>    return;
<a name="line269"></a>  }
<a name="line270"></a>  if (!this.hasChanged() &amp;&amp; !this.inFocusAndSelect_) {
<a name="line271"></a>    var me = this;
<a name="line272"></a>    var clearValue = function() {
<a name="line273"></a>      // Component could be disposed by the time this is called.
<a name="line274"></a>      if (me.getElement()) {
<a name="line275"></a>        me.getElement().value = &#39;&#39;;
<a name="line276"></a>      }
<a name="line277"></a>    };
<a name="line278"></a>    if (goog.userAgent.IE) {
<a name="line279"></a>      goog.Timer.callOnce(clearValue, 10);
<a name="line280"></a>    } else {
<a name="line281"></a>      clearValue();
<a name="line282"></a>    }
<a name="line283"></a>  }
<a name="line284"></a>};
<a name="line285"></a>
<a name="line286"></a>
<a name="line287"></a>/**
<a name="line288"></a> * Handler for the blur event.
<a name="line289"></a> * @param {goog.events.Event} e The event object passed in to the event handler.
<a name="line290"></a> * @private
<a name="line291"></a> */
<a name="line292"></a>goog.ui.LabelInput.prototype.handleBlur_ = function(e) {
<a name="line293"></a>  // We listen to the click event when we enter focusAndSelect mode so we can
<a name="line294"></a>  // fake an artificial focus when the user clicks on the input box. However,
<a name="line295"></a>  // if the user clicks on something else (and we lose focus), there is no
<a name="line296"></a>  // need for an artificial focus event.
<a name="line297"></a>  if (!goog.ui.LabelInput.SUPPORTS_PLACEHOLDER_) {
<a name="line298"></a>    this.eventHandler_.unlisten(
<a name="line299"></a>        this.getElement(), goog.events.EventType.CLICK, this.handleFocus_);
<a name="line300"></a>    this.ffKeyRestoreValue_ = null;
<a name="line301"></a>  }
<a name="line302"></a>  this.hasFocus_ = false;
<a name="line303"></a>  this.check_();
<a name="line304"></a>};
<a name="line305"></a>
<a name="line306"></a>
<a name="line307"></a>/**
<a name="line308"></a> * Handler for key events in Firefox.
<a name="line309"></a> *
<a name="line310"></a> * If the escape key is pressed when a text input has not been changed manually
<a name="line311"></a> * since being focused, the text input will revert to its previous value.
<a name="line312"></a> * Firefox does not honor preventDefault for the escape key. The revert happens
<a name="line313"></a> * after the keydown event and before every keypress. We therefore store the
<a name="line314"></a> * element&#39;s value on keydown and restore it on keypress. The restore value is
<a name="line315"></a> * nullified on keyup so that {@link #getValue} returns the correct value.
<a name="line316"></a> *
<a name="line317"></a> * IE and Chrome don&#39;t have this problem, Opera blurs in the input box
<a name="line318"></a> * completely in a way that preventDefault on the escape key has no effect.
<a name="line319"></a> *
<a name="line320"></a> * @param {goog.events.BrowserEvent} e The event object passed in to
<a name="line321"></a> *     the event handler.
<a name="line322"></a> * @private
<a name="line323"></a> */
<a name="line324"></a>goog.ui.LabelInput.prototype.handleEscapeKeys_ = function(e) {
<a name="line325"></a>  if (e.keyCode == 27) {
<a name="line326"></a>    if (e.type == goog.events.EventType.KEYDOWN) {
<a name="line327"></a>      this.ffKeyRestoreValue_ = this.getElement().value;
<a name="line328"></a>    } else if (e.type == goog.events.EventType.KEYPRESS) {
<a name="line329"></a>      this.getElement().value = /** @type {string} */ (this.ffKeyRestoreValue_);
<a name="line330"></a>    } else if (e.type == goog.events.EventType.KEYUP) {
<a name="line331"></a>      this.ffKeyRestoreValue_ = null;
<a name="line332"></a>    }
<a name="line333"></a>    e.preventDefault();
<a name="line334"></a>  }
<a name="line335"></a>};
<a name="line336"></a>
<a name="line337"></a>
<a name="line338"></a>/**
<a name="line339"></a> * Handler for the submit event of the form element.
<a name="line340"></a> * @param {goog.events.Event} e The event object passed in to the event handler.
<a name="line341"></a> * @private
<a name="line342"></a> */
<a name="line343"></a>goog.ui.LabelInput.prototype.handleFormSubmit_ = function(e) {
<a name="line344"></a>  if (!this.hasChanged()) {
<a name="line345"></a>    this.getElement().value = &#39;&#39;;
<a name="line346"></a>    // allow form to be sent before restoring value
<a name="line347"></a>    goog.Timer.callOnce(this.handleAfterSubmit_, 10, this);
<a name="line348"></a>  }
<a name="line349"></a>};
<a name="line350"></a>
<a name="line351"></a>
<a name="line352"></a>/**
<a name="line353"></a> * Restore value after submit
<a name="line354"></a> * @private
<a name="line355"></a> */
<a name="line356"></a>goog.ui.LabelInput.prototype.handleAfterSubmit_ = function() {
<a name="line357"></a>  if (!this.hasChanged()) {
<a name="line358"></a>    this.getElement().value = this.label_;
<a name="line359"></a>  }
<a name="line360"></a>};
<a name="line361"></a>
<a name="line362"></a>
<a name="line363"></a>/**
<a name="line364"></a> * Handler for the load event the window. This is needed because
<a name="line365"></a> * IE sets defaultValue upon load.
<a name="line366"></a> * @param {Event} e The event object passed in to the event handler.
<a name="line367"></a> * @private
<a name="line368"></a> */
<a name="line369"></a>goog.ui.LabelInput.prototype.handleWindowLoad_ = function(e) {
<a name="line370"></a>  this.check_();
<a name="line371"></a>};
<a name="line372"></a>
<a name="line373"></a>
<a name="line374"></a>/**
<a name="line375"></a> * @return {boolean} Whether the control is currently focused on.
<a name="line376"></a> */
<a name="line377"></a>goog.ui.LabelInput.prototype.hasFocus = function() {
<a name="line378"></a>  return this.hasFocus_;
<a name="line379"></a>};
<a name="line380"></a>
<a name="line381"></a>
<a name="line382"></a>/**
<a name="line383"></a> * @return {boolean} Whether the value has been changed by the user.
<a name="line384"></a> */
<a name="line385"></a>goog.ui.LabelInput.prototype.hasChanged = function() {
<a name="line386"></a>  return !!this.getElement() &amp;&amp; this.getElement().value != &#39;&#39; &amp;&amp;
<a name="line387"></a>      this.getElement().value != this.label_;
<a name="line388"></a>};
<a name="line389"></a>
<a name="line390"></a>
<a name="line391"></a>/**
<a name="line392"></a> * Clears the value of the input element without resetting the default text.
<a name="line393"></a> */
<a name="line394"></a>goog.ui.LabelInput.prototype.clear = function() {
<a name="line395"></a>  this.getElement().value = &#39;&#39;;
<a name="line396"></a>
<a name="line397"></a>  // Reset ffKeyRestoreValue_ when non-null
<a name="line398"></a>  if (this.ffKeyRestoreValue_ != null) {
<a name="line399"></a>    this.ffKeyRestoreValue_ = &#39;&#39;;
<a name="line400"></a>  }
<a name="line401"></a>};
<a name="line402"></a>
<a name="line403"></a>
<a name="line404"></a>/**
<a name="line405"></a> * Clears the value of the input element and resets the default text.
<a name="line406"></a> */
<a name="line407"></a>goog.ui.LabelInput.prototype.reset = function() {
<a name="line408"></a>  if (this.hasChanged()) {
<a name="line409"></a>    this.clear();
<a name="line410"></a>    this.check_();
<a name="line411"></a>  }
<a name="line412"></a>};
<a name="line413"></a>
<a name="line414"></a>
<a name="line415"></a>/**
<a name="line416"></a> * Use this to set the value through script to ensure that the label state is
<a name="line417"></a> * up to date
<a name="line418"></a> * @param {string} s The new value for the input.
<a name="line419"></a> */
<a name="line420"></a>goog.ui.LabelInput.prototype.setValue = function(s) {
<a name="line421"></a>  if (this.ffKeyRestoreValue_ != null) {
<a name="line422"></a>    this.ffKeyRestoreValue_ = s;
<a name="line423"></a>  }
<a name="line424"></a>  this.getElement().value = s;
<a name="line425"></a>  this.check_();
<a name="line426"></a>};
<a name="line427"></a>
<a name="line428"></a>
<a name="line429"></a>/**
<a name="line430"></a> * Returns the current value of the text box, returning an empty string if the
<a name="line431"></a> * search box is the default value
<a name="line432"></a> * @return {string} The value of the input box.
<a name="line433"></a> */
<a name="line434"></a>goog.ui.LabelInput.prototype.getValue = function() {
<a name="line435"></a>  if (this.ffKeyRestoreValue_ != null) {
<a name="line436"></a>    // Fix the Firefox from incorrectly reporting the value to calling code
<a name="line437"></a>    // that attached the listener to keypress before the labelinput
<a name="line438"></a>    return this.ffKeyRestoreValue_;
<a name="line439"></a>  }
<a name="line440"></a>  return this.hasChanged() ? /** @type {string} */ (this.getElement().value) :
<a name="line441"></a>      &#39;&#39;;
<a name="line442"></a>};
<a name="line443"></a>
<a name="line444"></a>
<a name="line445"></a>/**
<a name="line446"></a> * Sets the label text.
<a name="line447"></a> * @param {string} label The text to show as the label.
<a name="line448"></a> */
<a name="line449"></a>goog.ui.LabelInput.prototype.setLabel = function(label) {
<a name="line450"></a>  if (goog.ui.LabelInput.SUPPORTS_PLACEHOLDER_) {
<a name="line451"></a>    this.label_ = label;
<a name="line452"></a>    if (this.getElement()) {
<a name="line453"></a>      this.getElement().placeholder = this.label_;
<a name="line454"></a>    }
<a name="line455"></a>    return;
<a name="line456"></a>  }
<a name="line457"></a>  if (this.getElement() &amp;&amp; !this.hasChanged()) {
<a name="line458"></a>    this.getElement().value = &#39;&#39;;
<a name="line459"></a>  }
<a name="line460"></a>  this.label_ = label;
<a name="line461"></a>  this.restoreLabel_();
<a name="line462"></a>  var labelInputElement = this.getElement();
<a name="line463"></a>  // Check if this has been called before DOM structure building
<a name="line464"></a>  if (labelInputElement) {
<a name="line465"></a>    goog.a11y.aria.setState(labelInputElement,
<a name="line466"></a>        goog.a11y.aria.State.LABEL,
<a name="line467"></a>        this.label_);
<a name="line468"></a>  }
<a name="line469"></a>};
<a name="line470"></a>
<a name="line471"></a>
<a name="line472"></a>/**
<a name="line473"></a> * @return {string} The text to show as the label.
<a name="line474"></a> */
<a name="line475"></a>goog.ui.LabelInput.prototype.getLabel = function() {
<a name="line476"></a>  return this.label_;
<a name="line477"></a>};
<a name="line478"></a>
<a name="line479"></a>
<a name="line480"></a>/**
<a name="line481"></a> * Checks the state of the input element
<a name="line482"></a> * @private
<a name="line483"></a> */
<a name="line484"></a>goog.ui.LabelInput.prototype.check_ = function() {
<a name="line485"></a>  var labelInputElement = this.getElement();
<a name="line486"></a>  goog.asserts.assert(labelInputElement,
<a name="line487"></a>      &#39;The label input element cannot be null.&#39;);
<a name="line488"></a>  if (!goog.ui.LabelInput.SUPPORTS_PLACEHOLDER_) {
<a name="line489"></a>    // if we haven&#39;t got a form yet try now
<a name="line490"></a>    this.attachEventsToForm_();
<a name="line491"></a>    goog.a11y.aria.setState(labelInputElement,
<a name="line492"></a>        goog.a11y.aria.State.LABEL,
<a name="line493"></a>        this.label_);
<a name="line494"></a>  } else if (this.getElement().placeholder != this.label_) {
<a name="line495"></a>    this.getElement().placeholder = this.label_;
<a name="line496"></a>  }
<a name="line497"></a>
<a name="line498"></a>  if (!this.hasChanged()) {
<a name="line499"></a>    if (!this.inFocusAndSelect_ &amp;&amp; !this.hasFocus_) {
<a name="line500"></a>      var el = this.getElement();
<a name="line501"></a>      goog.asserts.assert(el);
<a name="line502"></a>      goog.dom.classlist.add(el, this.LABEL_CLASS_NAME);
<a name="line503"></a>    }
<a name="line504"></a>
<a name="line505"></a>    // Allow browser to catchup with CSS changes before restoring the label.
<a name="line506"></a>    if (!goog.ui.LabelInput.SUPPORTS_PLACEHOLDER_) {
<a name="line507"></a>      goog.Timer.callOnce(this.restoreLabel_, this.labelRestoreDelayMs,
<a name="line508"></a>          this);
<a name="line509"></a>    }
<a name="line510"></a>  } else {
<a name="line511"></a>    var el = this.getElement();
<a name="line512"></a>    goog.asserts.assert(el);
<a name="line513"></a>    goog.dom.classlist.remove(el, this.LABEL_CLASS_NAME);
<a name="line514"></a>  }
<a name="line515"></a>};
<a name="line516"></a>
<a name="line517"></a>
<a name="line518"></a>/**
<a name="line519"></a> * This method focuses the input and selects all the text. If the value hasn&#39;t
<a name="line520"></a> * changed it will set the value to the label so that the label text is
<a name="line521"></a> * selected.
<a name="line522"></a> */
<a name="line523"></a>goog.ui.LabelInput.prototype.focusAndSelect = function() {
<a name="line524"></a>  // We need to check whether the input has changed before focusing
<a name="line525"></a>  var hc = this.hasChanged();
<a name="line526"></a>  this.inFocusAndSelect_ = true;
<a name="line527"></a>  this.getElement().focus();
<a name="line528"></a>  if (!hc &amp;&amp; !goog.ui.LabelInput.SUPPORTS_PLACEHOLDER_) {
<a name="line529"></a>    this.getElement().value = this.label_;
<a name="line530"></a>  }
<a name="line531"></a>  this.getElement().select();
<a name="line532"></a>
<a name="line533"></a>  // Since the object now has focus, we won&#39;t get a focus event when they
<a name="line534"></a>  // click in the input element. The expected behavior when you click on
<a name="line535"></a>  // the default text is that it goes away and allows you to type...so we
<a name="line536"></a>  // have to fire an artificial focus event when we&#39;re in focusAndSelect mode.
<a name="line537"></a>  if (goog.ui.LabelInput.SUPPORTS_PLACEHOLDER_) {
<a name="line538"></a>    return;
<a name="line539"></a>  }
<a name="line540"></a>  if (this.eventHandler_) {
<a name="line541"></a>    this.eventHandler_.listenOnce(
<a name="line542"></a>        this.getElement(), goog.events.EventType.CLICK, this.handleFocus_);
<a name="line543"></a>  }
<a name="line544"></a>
<a name="line545"></a>  // set to false in timer to let IE trigger the focus event
<a name="line546"></a>  goog.Timer.callOnce(this.focusAndSelect_, 10, this);
<a name="line547"></a>};
<a name="line548"></a>
<a name="line549"></a>
<a name="line550"></a>/**
<a name="line551"></a> * Enables/Disables the label input.
<a name="line552"></a> * @param {boolean} enabled Whether to enable (true) or disable (false) the
<a name="line553"></a> *     label input.
<a name="line554"></a> */
<a name="line555"></a>goog.ui.LabelInput.prototype.setEnabled = function(enabled) {
<a name="line556"></a>  this.getElement().disabled = !enabled;
<a name="line557"></a>  var el = this.getElement();
<a name="line558"></a>  goog.asserts.assert(el);
<a name="line559"></a>  goog.dom.classlist.enable(el,
<a name="line560"></a>      goog.getCssName(this.LABEL_CLASS_NAME, &#39;disabled&#39;), !enabled);
<a name="line561"></a>};
<a name="line562"></a>
<a name="line563"></a>
<a name="line564"></a>/**
<a name="line565"></a> * @return {boolean} True if the label input is enabled, false otherwise.
<a name="line566"></a> */
<a name="line567"></a>goog.ui.LabelInput.prototype.isEnabled = function() {
<a name="line568"></a>  return !this.getElement().disabled;
<a name="line569"></a>};
<a name="line570"></a>
<a name="line571"></a>
<a name="line572"></a>/**
<a name="line573"></a> * @private
<a name="line574"></a> */
<a name="line575"></a>goog.ui.LabelInput.prototype.focusAndSelect_ = function() {
<a name="line576"></a>  this.inFocusAndSelect_ = false;
<a name="line577"></a>};
<a name="line578"></a>
<a name="line579"></a>
<a name="line580"></a>/**
<a name="line581"></a> * Sets the value of the input element to label.
<a name="line582"></a> * @private
<a name="line583"></a> */
<a name="line584"></a>goog.ui.LabelInput.prototype.restoreLabel_ = function() {
<a name="line585"></a>  // Check again in case something changed since this was scheduled.
<a name="line586"></a>  // We check that the element is still there since this is called by a timer
<a name="line587"></a>  // and the dispose method may have been called prior to this.
<a name="line588"></a>  if (this.getElement() &amp;&amp; !this.hasChanged() &amp;&amp; !this.hasFocus_) {
<a name="line589"></a>    this.getElement().value = this.label_;
<a name="line590"></a>  }
<a name="line591"></a>};
</pre>


</body>
</html>
